import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpServer {
    private DatagramSocket datagramSocket= null;

    public UdpServer(int n) throws SocketException {
        datagramSocket = new DatagramSocket(n);
    }
    public void start() throws IOException {
        while(true) {
            DatagramPacket datagramPacket =  new DatagramPacket(new byte[4096],4096);
            datagramSocket.receive(datagramPacket);
            String arr1 = datagramPacket.getData().toString();
            String arr2 = fangfa(arr1);
            DatagramPacket datagramPacket1 = new DatagramPacket(arr2.getBytes(),arr2.getBytes().length,datagramPacket.getSocketAddress());
            datagramSocket.send(datagramPacket1);
        }
    }
    public String fangfa(String arr) {
        return arr;
    }
}
